package com.xuan.chatroom.model;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result <T> {

    private int code;   // 业务状态码  -1: 失败   -2:未登录   200成功
    private String message;
    private T data;

    // 成功
    public static <T> Result<T>  success(T data) {
        return new Result<>(200, "", data);
    }

    // 失败
    public static <T> Result<T> fail(String errMsg) {
        return new Result<>(-1, errMsg, null);
    }
    public static <T> Result<T> fail(String errMsg, T data) {
        return new Result<>(-1, errMsg, data);
    }

    // 未登录
    public static <T> Result<T> unLogin() {
        return new Result<>(-2, "用户未登录", null);
    }
}
